package com.ase.springsecurity.controller;

import com.ase.springsecurity.entity.mongodb.Blog;
import com.ase.springsecurity.entity.mongodb.UserMongoDB;
import com.ase.springsecurity.result.Result;
import com.ase.springsecurity.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gyhstart
 * @create 2020/12/27 - 22:39
 **/

@RestController
@RequestMapping("mongodb")
public class BlogController {

    @Autowired
    private BlogService blogService;

    /**
     * MongoDB 增加
     *
     * @param blog
     */
    @PostMapping("/saveBlog")
    public Result saveMongoDB(@RequestBody Blog blog) {
        int blogMongoDB = blogService.saveBlogMongoDB(blog);
        return Result.success(blogMongoDB);
    }

    /**
     * MongoDB 删除
     * @param id
     */
    @DeleteMapping("/removeBlog")
    public void removeMongoDB(@RequestParam("id") long id){
        blogService.removeBlogMongoDB(id);
    }

    /**
     * MongoDB 修改
     * @param blog
     */
    @PutMapping("/modifyBlog")
    public void updateMongoDB(@RequestBody Blog blog){
        blogService.modifyBlogMongoDB(blog);
    }

    /**
     * MongoDB 查询所有
     * @return
     */
    @GetMapping("/queryBlogAllList")
    public Result queryAllBlog(){
        List<Blog> blogList = blogService.queryAllBlogMongoDB();
        return Result.success(blogList);
    }

    /**
     * MongoDB 模糊查询
     * @return
     */
    @GetMapping("/queryFuzzyBlogList")
    public Result queryFuzzyBlog(@RequestParam("title") String title){
        List<Blog> blogList = blogService.queryFuzzyBlogMongoDB(title);
        return Result.success(blogList);
    }
}
